package cn.seaboot.admin.rabbit.test;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author Mr.css
 * @version 2021-06-23 16:52
 */
public class ConnectionUtil {
    private static final Logger logger = LoggerFactory.getLogger(ConnectionUtil.class);

    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        // 设置服务端地址（域名地址/ip）
//        factory.setHost("127.0.0.1");
        factory.setHost("47.122.57.10");
        // 设置服务器端口号，最易犯的错误就是填写为15672(网页端口),正确为5672
        factory.setPort(5672);
        // 设置虚拟主机(相当于数据库中的库)
        factory.setVirtualHost("/");
        // 设置用户名
        factory.setUsername("admin");
        // 设置密码
        factory.setPassword("maker");
        return factory.newConnection();
    }

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = getConnection();
        System.out.println(connection);
        connection.close();
    }
}
